<?php
	class Article_model extends CI_Model {
		public $table_name='article';
	    public function get_article(){
	        $query = $this->db->get($this->table_name);
	        return $query->result();
	    }
	    public function get_one($id){
	    	$query=$this->db->where("id",$id)->get($this->table_name);
	    	return $query->row();
	    }
	    public function get_catalog_id($catalog_id){
	    	$query=$this->db->where("catalog_id",$catalog_id)->get($this->table_name);
	    	return $query->result();
	    }
	    public function viewadd($id){
	    	$this->db->query("update $this->table_name set `view`=`view`+1 where id= $id");  
	    }
	    public function countall(){
	    	return $this->db->count_all_results($this->table_name);
	    }
	    public function get_by_page($page,$page_size){
	    	$offset=($page-1)*$page_size;
	    	$query=$this->db->limit($page_size,$offset)->order_by('id','DESC')->get($this->table_name);
	    	return $query->result();
	    }
	    public function add_one($data){
			$data['create_time']=time();
	    	$this->db->insert($this->table_name, $data);
	    }
	    public function edit_one($id,$data){
	    	$this->db->where('id', $id);
	    	$this->db->update($this->table_name, $data);
	    }
	    public function del_id($id){
			$this->db->where('id', $id);
			$query=$this->db->delete($this->table_name);
	    }
	    public function set_recommend($i,$j){
	    	$data=array(
	    		'recommend'=>$j,
	    		);
	    	$this->db->where('id', $i)->update($this->table_name, $data);
	    }
	}
?>
